#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <iostream>

const char * IP_ADDR = "192.158.125.249";
const int    PORT    = 18001;

using namespace std ;

int main ( )
{
	int sockfd ;
	int len ;
	struct sockaddr_in address ;
	int result ;
	char str[255] ;

	sockfd = socket(AF_INET, SOCK_STREAM, 0) ;
	address.sin_family = AF_INET;
	address.sin_addr.s_addr = inet_addr(IP_ADDR) ;
	address.sin_port = htons(PORT) ;
	len = sizeof(address) ;

	result = connect(sockfd, (struct sockaddr *)&address, len);
	if ( result == -1 )
	{
		perror("oops: client1") ;
		exit(1) ;
	}

    char *pStr = "Hello Server\n" ;

    write(sockfd, pStr, strlen(pStr)+1) ;

	read(sockfd, str, 255) ;
	cout<< "Messages from server: " << endl ;
	cout<< str ;
	sleep(5) ;
	close(sockfd) ;
	
	return 0 ;
}
